---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment Analysis/03_
> Logs/20240426_lasso_prep_finance.log
  log type:  text
 opened on:  26 Apr 2024, 00:09:54

. 
. 
. global finance_data "$cleaned/finance"

. 
. /*----------------------------------------------------*/
.             /* Section: SUSENAS Finance */
. /*----------------------------------------------------*/
. 
. local merge_type_finance_treats = "1:1"

. local merge_type_finance_ind    = "m:1"

. 
. foreach survey in mar19 {
  2. 
.         foreach data in finance_treats finance_ind { //
  3. 
.                 di "`survey': `data'"
  4.                 u "$cleaned/finance/susenas_`survey'_`data'.dta", clear
  5. 
.         * merge in baseline susenas for lasso controls
.                 gen id_jan14 = KABU
  6.                 qui forvalues year = 2016 / 2018 {
  7.                         merge m:1 id_jan14 urban using "$cleaned/mar_`year'_baseline_pool"
  8.                         assert _m != 1
  9.                         keep if _m == 3
 10.                         drop _m
 11.                 }
 12.                 drop id_jan14
 13. 
.         ** merge in UDB
.                 * mar 19
.                 if "`survey'" == "mar19" {
 14.                         rename RENUM renum
 15.                         merge `merge_type_`data'' renum using "$cleaned/mar_2019_udb_lasso_pool.dta"
 16.                 }
 17. 
.                 * sep 18
.                 else {
 18.                         rename URUT2 urut2
 19.                         merge `merge_type_`data'' urut2 using "$cleaned/sep_2018_udb_lasso_pool.dta"
 20.                 }
 21. 
.                 assert _m != 1
 22.                 keep if _m == 3
 23.                 drop _m
 24. 
.                 * PMT score cutoffs
.                 foreach cut in 5 10 15 20 25 30  {
 25.                         gen pmt`cut' = percentile_udb <= `cut' & percentile_m_udb == 0
 26.                 }
 27.                 gen above = percentile_udb > 30 | udb == 0
 28.                 gen all = 1
 29.                 gen pmt50 = percentile_udb > 50 | udb == 0
 30. 
.         ** PODES
.                 cap rename r103 R103
 31.                 cap rename r104 R104
 32.                 merge m:1 R101 R102 R103 R104 using "$cleaned/podes_2018.dta"
 33.                 // assert _m != 1
.                 drop if _m == 2
 34.                 drop _m
 35. 
.         ** merge in village agent data
.                 * prep mar 18 village data
.                 preserve
 36.                 if "`survey'" == "sep18" {
 37.                         u "$cleaned/finance/aug18_village_IE_treats.dta", clear
 38.                 }
 39.                 else {
 40.                         u "$cleaned/finance/`survey'_village_IE_treats.dta", clear
 41. 
.                 }
 42.                 qui destring Kode_Provinsi, gen(R101)
 43.                 qui destring Kode_Kabupaten, gen(R102)
 44.                 qui destring Kode_Kecamatan, gen(R103)
 45.                 qui destring Kode_Desa, gen(R104)
 46.                 keep R101 R102 R103 R104 *mar18 beneficiaries num_agents_bpnt num_agents_total agent_ratio_bpnt agent_
> ratio_total at_least_2_bpnt at_least_2_total
 47.                 tempfile village_agent
 48.                 qui save `village_agent'
 49.                 restore
 50. 
.                 * merge
.                 merge m:1 R101 R102 R103 R104 using `village_agent'
 51.                 drop if _m == 2
 52.                 qui count if _m == 1
 53.                 di "`r(N)' obs missing village-level agent data"
 54.                 drop _m
 55. 
.                 * save
.                 save "$cleaned/finance/susenas_`survey'_`data'_lasso.dta", replace
 56.         }
 57. 
. }
mar19: finance_treats

    Result                      Number of obs
    -----------------------------------------
    Not matched                       249,176
        from master                         0  (_merge==1)
        from using                    249,176  (_merge==2)

    Matched                            66,496  (_merge==3)
    -----------------------------------------
(249,176 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                        78,222
        from master                         9  (_merge==1)
        from using                     78,213  (_merge==2)

    Matched                            66,487  (_merge==3)
    -----------------------------------------
(78,213 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                        15,854
        from master                       758  (_merge==1)
        from using                     15,096  (_merge==2)

    Matched                            65,738  (_merge==3)
    -----------------------------------------
(15,096 observations deleted)
758 obs missing village-level agent data
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/susenas_mar19_finance_treats_lasso.dta saved
mar19: finance_ind

    Result                      Number of obs
    -----------------------------------------
    Not matched                       249,176
        from master                         0  (_merge==1)
        from using                    249,176  (_merge==2)

    Matched                           251,114  (_merge==3)
    -----------------------------------------
(249,176 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                        78,251
        from master                        38  (_merge==1)
        from using                     78,213  (_merge==2)

    Matched                           251,076  (_merge==3)
    -----------------------------------------
(78,213 observations deleted)

    Result                      Number of obs
    -----------------------------------------
    Not matched                        18,059
        from master                     2,963  (_merge==1)
        from using                     15,096  (_merge==2)

    Matched                           248,151  (_merge==3)
    -----------------------------------------
(15,096 observations deleted)
2963 obs missing village-level agent data
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/susenas_mar19_finance_ind_lasso.dta saved

. 
. 
. 
. 
. 
. *** Impact eval village dataset
. * Merge in PODES into village-level agent datasets
. foreach data in aug18 mar19 {
  2.   u "$cleaned/finance/`data'_village_IE_treats.dta", clear
  3. 
.   // rename for merge
.   destring Kode_Provinsi, gen(R101)
  4.   destring Kode_Kabupaten, gen(R102)
  5.   destring Kode_Kecamatan, gen(R103)
  6.   destring Kode_Desa, gen(R104)
  7. 
.   merge 1:1 R101 R102 R103 R104 using "$cleaned/podes_2018.dta"
  8.   drop if _m == 2
  9.   drop _m
 10. 
.   * 218 villages not in PODES
.   * Recode so that they are 0s and equal to 1 in the missing dummies
.   foreach var of varlist *podes {
 11.     di "`var'"
 12. 
.     // if the podes control is not a missing dummy, make the missing villages 0
.     if strpos("`var'", "miss") == 0 {
 13.       replace `var' = 0 if `var' == .
 14.     }
 15.     // else, then the podes control is a missing dummy, so make it 1
.     else {
 16.       replace `var' = 1 if `var' == .
 17.     }
 18.   }
 19. 
.         // create log beneficiaries
.         gen log_beneficiaries = ln(beneficiaries)
 20. 
.         // rename vars to shorten
.         rename num_agents_w_bpnt  num_agentsw_bpnt
 21.         rename agent_ratio_w_bpnt         agent_ratiow_bpnt
 22.         gen num_agentsw_mar18 = num_agents_mar18
 23.         gen agent_ratiow_mar18 = agent_ratio_mar18
 24.         la var num_agentsw_mar18         "\# Agents In Village (Baseline)"
 25.         la var agent_ratiow_mar18        "Agents Per Beneficiary (Baseline)"
 26. 
.         rename num_agents*               agents*
 27.         rename agent_ratio*     ratio*
 28.         rename both_criteria*   both*
 29.         rename at_least_2*              min2*
 30. 
.         // encode bank variable
.         encode himbara, gen(bank)
 31. 
.   save "$cleaned/finance/`data'_village_IE_treats_lasso.dta", replace
 32. }
Kode_Provinsi: all characters numeric; R101 generated as byte
Kode_Kabupaten: all characters numeric; R102 generated as byte
Kode_Kecamatan: all characters numeric; R103 generated as int
Kode_Desa: all characters numeric; R104 generated as int

    Result                      Number of obs
    -----------------------------------------
    Not matched                        63,560
        from master                       186  (_merge==1)
        from using                     63,374  (_merge==2)

    Matched                            20,557  (_merge==3)
    -----------------------------------------
(63,374 observations deleted)
himbara_bank_podes
(186 real changes made)
dist_himbara_bank_podes
(186 real changes made)
private_bank_podes
(186 real changes made)
dist_private_bank_podes
(186 real changes made)
atm_podes
(186 real changes made)
distance_atm_podes
(186 real changes made)
agent_podes
(186 real changes made)
distance_agent_podes
(186 real changes made)
rice_agri_podes
(186 real changes made)
non_rice_agri_podes
(186 real changes made)
non_agri_podes
(186 real changes made)
miss_agri_podes
(186 real changes made)
asphalt_road_transport_podes
(186 real changes made)
gravel_road_transport_podes
(186 real changes made)
land_transport_podes
(186 real changes made)
water_transport_podes
(186 real changes made)
other_transport_podes
(186 real changes made)
miss_transport_podes
(186 real changes made)
road_passable_always_podes
(186 real changes made)
road_passable_usually_podes
(186 real changes made)
road_passable_dry_season_podes
(186 real changes made)
road_passable_never_podes
(186 real changes made)
road_passable_missing_podes
(186 real changes made)
distance_camat_podes
(186 real changes made)
distance_camat_miss_podes
(186 real changes made)
time_to_camat_podes
(186 real changes made)
time_to_camat_miss_podes
(186 real changes made)
fees_camat_podes
(186 real changes made)
fees_camat_miss_podes
(186 real changes made)
vstrong_cell_signal_podes
(186 real changes made)
strong_cell_signal_podes
(186 real changes made)
weak_cell_signal_podes
(186 real changes made)
no_cell_signal_podes
(186 real changes made)
miss_cell_signal_podes
(186 real changes made)
internet_cell_4G_podes
(186 real changes made)
internet_cell_3G_podes
(186 real changes made)
internet_cell_25G_podes
(186 real changes made)
internet_cell_none_podes
(186 real changes made)
internet_cell_miss_podes
(186 real changes made)
desa_head_edu18_podes
(186 real changes made)
desa_head_edu18_missing_podes
(186 real changes made)
no_bankaccess_podes
(186 real changes made)
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/aug18_village_IE_treats_lasso.dta saved
Kode_Provinsi: all characters numeric; R101 generated as byte
Kode_Kabupaten: all characters numeric; R102 generated as byte
Kode_Kecamatan: all characters numeric; R103 generated as int
Kode_Desa: all characters numeric; R104 generated as int

    Result                      Number of obs
    -----------------------------------------
    Not matched                        63,560
        from master                       186  (_merge==1)
        from using                     63,374  (_merge==2)

    Matched                            20,557  (_merge==3)
    -----------------------------------------
(63,374 observations deleted)
himbara_bank_podes
(186 real changes made)
dist_himbara_bank_podes
(186 real changes made)
private_bank_podes
(186 real changes made)
dist_private_bank_podes
(186 real changes made)
atm_podes
(186 real changes made)
distance_atm_podes
(186 real changes made)
agent_podes
(186 real changes made)
distance_agent_podes
(186 real changes made)
rice_agri_podes
(186 real changes made)
non_rice_agri_podes
(186 real changes made)
non_agri_podes
(186 real changes made)
miss_agri_podes
(186 real changes made)
asphalt_road_transport_podes
(186 real changes made)
gravel_road_transport_podes
(186 real changes made)
land_transport_podes
(186 real changes made)
water_transport_podes
(186 real changes made)
other_transport_podes
(186 real changes made)
miss_transport_podes
(186 real changes made)
road_passable_always_podes
(186 real changes made)
road_passable_usually_podes
(186 real changes made)
road_passable_dry_season_podes
(186 real changes made)
road_passable_never_podes
(186 real changes made)
road_passable_missing_podes
(186 real changes made)
distance_camat_podes
(186 real changes made)
distance_camat_miss_podes
(186 real changes made)
time_to_camat_podes
(186 real changes made)
time_to_camat_miss_podes
(186 real changes made)
fees_camat_podes
(186 real changes made)
fees_camat_miss_podes
(186 real changes made)
vstrong_cell_signal_podes
(186 real changes made)
strong_cell_signal_podes
(186 real changes made)
weak_cell_signal_podes
(186 real changes made)
no_cell_signal_podes
(186 real changes made)
miss_cell_signal_podes
(186 real changes made)
internet_cell_4G_podes
(186 real changes made)
internet_cell_3G_podes
(186 real changes made)
internet_cell_25G_podes
(186 real changes made)
internet_cell_none_podes
(186 real changes made)
internet_cell_miss_podes
(186 real changes made)
desa_head_edu18_podes
(186 real changes made)
desa_head_edu18_missing_podes
(186 real changes made)
no_bankaccess_podes
(186 real changes made)
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/mar19_village_IE_treats_lasso.dta saved

. 
. *** create pooled dataset
. // load aug 18 dataset
. u "$cleaned/finance/aug18_village_IE_treats_lasso.dta", clear

. // summ
. gen wave = 0

. keep kodewilayah agents* agents_mar18 agentsw* ratio* ratio_mar18 ratiow* both* ratio250* min2* ///
>         treated_sep18 *beneficiaries Provinsi Kabupaten idkab *podes wave finalstratum bank *bank ///
> 

. 
. preserve

. u "$cleaned/finance/mar19_village_IE_treats_lasso.dta", clear

. // summ
. gen wave = 1

. keep kodewilayah agents* agents_mar18 agentsw* ratio* ratio_mar18 ratiow* both* ratio250* min2* ///
>         treated *beneficiaries Provinsi Kabupaten idkab *podes wave finalstratum

. tempfile mar19_village

. save `mar19_village'
file /var/folders/23/7_md6wbn6ns7m_ppp9yb96sh0000gp/T//S_18300.000006 saved as .dta format

. restore

. 
. append using `mar19_village'
(variable kodewilayah was str10, now str29 to accommodate using data's values)

. 
. // Identify variables that are not present in both March and Sep lasso pools
. local missing_vars = ""

. foreach var of varlist *podes {
  2.         cap assert `var' != .
  3.         if _rc != 0 {
  4.                 di "`var'"
  5.                 local missing_vars = "`missing_vars' `var'"
  6.         }
  7. }

. // none missing
. // summ *total
. 
. * create stack treat
. gen stack_treat = treated_sep18 == 1 & wave == 0 if wave == 0
(20,743 missing values generated)

. replace stack_treat = treated == 1 & wave == 1 if wave == 1
(20,743 real changes made)

. // tab stack_treat treated_sep18 if wave == 0
. // tab stack_treat treated if wave == 1
. 
. * Create wave-interacted variables
. rename *_podes podes_*

. ds podes*
podes_himb~k  podes_agent   podes_asph~t  podes_road~s  podes_dist~s  podes_stro~l  podes_in~25G
podes_dist..  podes_dis~nt  podes_grav~t  podes_road~y  podes_time~t  podes_weak~l  podes_inte~e
podes_priv~k  podes_rice~i  podes_land~t  podes_road~n  podes_time~s  podes_no_c~l  podes_inte~s
podes_dist..  podes_non_r~  podes_wate~t  podes_road~r  podes_fees~t  podes_miss~l  podes_des~18
podes_atm     podes~n_agri  podes_othe~t  podes_road~g  podes_fees~s  podes_int~4G  podes_desa~g
podes_dist~m  podes_miss~i  podes_miss~t  podes_dis~at  podes_vstr~l  podes_int~3G  podes_no_b~s

. 
. foreach var of varlist *mar18 podes* *beneficiaries {
  2.         if length("`var'W") > 32 {
  3.                 local newname = substr("`var'", 1, 31)
  4.                 gen `newname'W = wave * `var'
  5.                 di "`var' wave interaction named `newname'W"
  6.         }
  7.         else {
  8.                 gen `var'W = wave * `var'
  9.         }
 10. }

. 
. // asssert no missing values in lasso pool vars
. foreach var of varlist *mar18 podes* *beneficiaries *W {
  2.         cap        assert `var' != .
  3.         if _rc != 0 {
  4.                 di "`var'"
  5.         }
  6. }

. 
. save "$cleaned/finance/stacked_village_IE_treats_lasso.dta", replace
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/finance/stacked_village_IE_treats_lasso.dta saved

. 
. 
. 
. /*----------------------------------------------------*/
.             /* Section: PODES 2019 Finance */
. /*----------------------------------------------------*/
. 
. u "$finance_data/mar19_village_IE_treats_lasso.dta", clear

. 
. merge 1:1 R101 R102 R103 R104 using "$cleaned/podes_2019.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                        63,610
        from master                       208  (_merge==1)
        from using                     63,402  (_merge==2)

    Matched                            20,535  (_merge==3)
    -----------------------------------------

. 
. keep if _merge == 3
(63,610 observations deleted)

. 
. drop _merge

. 
. // Merge in 2018 info for controls
. 
. // drop _merge
. 
. // merge 1:1 R101 R102 R103 R104 using "$cleaned/podes_2018.dta"
. 
. // drop if _merge == 2
. 
. // drop _merge
. 
. 
. save "$cleaned/podes_2019_oursample.dta", replace
file /Users/clotairemit.edu/Dropbox (MIT)/J-PAL Raskin Transition/10_Analysis&Results/Agent Experiment
    Analysis/01_Data/cleaned/podes_2019_oursample.dta saved

. 
. cap log close
